﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DiscreteEventModel {

    using Common;

    public abstract partial class DiscreteState<TContext> : DiscreteEvent<TContext> {

        public DiscreteTime Time { get; private set; }
        protected override bool Traceable { get { return false; } }
        protected abstract void OnSynchronize(double timeStep);
        protected abstract void OnOutput(IRuntime runtime);
        
        public void Synchronize(IRuntime runtime) {
            this.OnSynchronize(runtime.Time - this.Time);
            this.Time = runtime.Time;
        }

        protected override DiscreteTime Commit(IRuntime runtime) {
            this.Synchronize(runtime);
            this.OnOutput(runtime);
            return this.Resolve(runtime.Context);
        }

        protected DiscreteState(IRuntime runtime){
            this.Time = runtime.Time;
        }
    }
}
